var array = [1, 2, 3]
var str = "a"
console.log("array:"+array);
console.log("join:"+array.join("-"));//1-2-3
console.log("join_array"+array);//1-2-3

console.log(array.join(str));//1a2a3
function repeatString(str, n) {
    return new Array(n + 1).join(str);


}

console.log(repeatString("a", 3));
console.log(repeatString("Hi", 5));

console.log("reverse:" + array.reverse());//[3,2,1]
console.log("reverse_array:" + array);//[3,2,1] reverse修改了原来的数组

/* soft 按字符串排序,修改原来的数组 */

console.log(array.sort((a, b) => a - b));

var arr = [{ age: 25 }, { age: 14 }, { age: 56 }];

console.log(arr.sort((a, b) => a.age - b.age));
arr.forEach(function (item) {
    console.log('age', item.age);

})

/*concat不修改原来的数组，连接*/
console.log("array:"+array);

console.log("concat:"+array.concat(4, 5));//[1,2,3,4,5]
console.log("concat_array:"+array);


console.log(array.concat([10, 11], 12));

console.log(array.concat([7, 8, [9, 10]]));
/*slice(起始闭索引，结束开索引) */
var b = [1, 2, 3, 4, 5]

console.log('slice:' + b.slice(1, 3)); console.log('slice_array:' + b);
console.log('slice:' + b.slice(1)); console.log('slice_array:' + b);
console.log('slice:' + b.slice(0)); console.log('slice_array:' + b);
console.log('slice:' + b.slice(1, -1)); console.log('slice_array:' + b);
/*splice(起始索引，删除个数) */
b = [1, 2, 3, 4, 5]
console.log("array:" + b);
console.log("splice:" + b.splice(1));//从索引1开始裁剪，原数组剩下
console.log("splice_array:" + b);
b = [1, 2, 3, 4, 5]
console.log("array:" + b);
console.log("splice:" +b.splice(1, 2));//从索引1开始裁剪2个，原数组剩下
console.log("splice_array:" +b);
b = [1, 2, 3, 4, 5]
console.log("array:" + b);
console.log("splice:" +b.splice(1, 2, 'a', "b"));//从索引1开始裁剪2个，原数组剩下
console.log("splice_array:" +b);

